XORRISOFLAGS = -as mkisofs --efi-boot limine/limine-uefi-cd.bin
# "-b sys/limine-bios-cd.bin -no-emul-boot -boot-info-table"

all: tkernel.iso
	@echo "Complete!"

kernel.bin: main.o hal.o boot.o loader.o
	ld boot.o main.o hal.o loader.o vfs.o -b elf64-x86-64 -T ./linker.lds -z muldefs -o kernel.bin
	# @cp kernel.bin

main.o:
	# make -C core clean
	make -C core build

hal.o:
	cd HAL
	# make -C hal clean
	make -C hal build

boot.o:
	cd boot
	# make -C boot clean
	make -C boot build

clean:
	# @rm main.o hal.o boot.o loader.o
	@rm *.o
	@make -C module/loader clean
	@make -C boot clean
	@make -C hal clean
	@make -C core clean
	@rm -rf ./iso
	@rm kernel.bin
	@rm tkernel.iso

loader.o:
	make -C module/loader clean
	make -C module/loader build

rebuild:
	make clean
	make run

tkernel.iso: kernel.bin
	@mkdir iso
	@cp -r ./assets/rootfs/* ./iso/
	@cp ./kernel.bin ./iso/kernel
	@touch ./tkernel.iso
	xorriso $(XORRISOFLAGS) ./iso ./tkernel.iso -o ./tkernel.iso \
	 2> /dev/null
	rm -rf ./iso

run: tkernel.iso
	qemu-system-amd64 -bios OVMF.fd -cdrom tkernel.iso

run_db: tkernel.iso
	qemu-system-amd64 -bios OVMF.fd -cdrom tkernel.iso -no-reboot -d in_asm,int >./debug.txt



